﻿@model MvcCmsProjectTracker.ViewModels.TicketEditViewModel
@using MvcCms.Service.Helpers;           
@{
    bool isAdmin = (Roles.IsUserInRole("Admin") || Roles.IsUserInRole("HelpDeskAdmin"));    
}           
@section HtmlHead{
    <link href="@Url.Content("/content/ckeditor.css") rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        function ClearCommentText() {
            $('#comment').val("");
        }
    </script>
}
<h2>
    Ticket:@Model.Ticket.TicketID
</h2>
<div style="position: relative;">
    <form id="form1" action="" method="post">
    <div id="actionbuttons" style="width: 800px; text-align: right;">
        <p>
            <a href="/projecttracker/Project/@Model.ActiveProjectID/Ticket/MyHelpDesk" class="button">My Help Desk</a>            
        </p>
    </div>
    <hr />
    <div class="editor-label" style="float: left; width: 150px">
        @Html.LabelFor(model => model.Ticket.Title):
    </div>
    <div class="editor-field" style="float: left;">
        @Model.Ticket.Title
    </div>
    <div class="clear">
    </div>
    <div class="editor-label" style="float: left; width: 150px">
        @Html.LabelFor(model => model.Ticket.LastUpdate):
    </div>
    <div class="editor-field" style="float: left;">
        @String.Format("{0:g}", Model.Ticket.LastUpdate)
    </div>
    <div class="clear">
    </div>
    <hr />
    <div style="float: left; width: 430px">
        <div class="editor-label" style="float: left; width: 150px">
            @Html.Label("Assigned To"):
        </div>
        <div class="editor-field" style="float: left;">
            @if (Model.Ticket.AssignedTo != null)
            {
                @Model.Ticket.AssignedTo.UserName
            }
            else
            {
                @:Not Set
            }        
        </div>
        <div class="clear">
        </div>
        <div class="editor-label" style="float: left; width: 150px">
            @Html.Label("Created By"):
        </div>
        <div class="editor-field" style="float: left;">
            @Model.Ticket.CreatedBy.UserName.Replace(".com", "").Replace(".net", "").Replace(".org", "")
        </div>
        <div class="clear">
        </div>
        <div class="editor-label" style="float: left; width: 150px">
            @Html.LabelFor(model => model.Ticket.DateCreated):
        </div>
        <div class="editor-field" style="float: left;">
            @String.Format("{0:g}", Model.Ticket.DateCreated)
        </div>
        <div class="clear">
        </div>
        <div class="editor-label" style="float: left; width: 150px">
            Project:
        </div>
        <div class="editor-field" style="float: left;">
            @Model.ProjectName
        </div>
        <div class="clear">
        </div>
    </div>
    <div style="float: left">
        <div class="editor-label" style="float: left; width: 150px">
            @Html.Label("Status"):
        </div>
        <div class="editor-field" style="float: left;">            
            @if (Model.Ticket.StatusID != null)
            { 
                @Model.Ticket.ProjectStatus.Name
                <img id="statusurl" src="@Url.Content(Model.ProjectStatuses.SingleOrDefault(s => s.StatusID == Model.Ticket.StatusID).ImageUrl)" alt="" />
            }
        </div>
        <div class="clear">
        </div>
        <div class="editor-label" style="float: left; width: 150px">
            @Html.Label("Priority"):
        </div>
        <div class="editor-field" style="float: left;">            
            @if (Model.Ticket.PriorityID != null)
            { 
                @Model.Ticket.ProjectPriority.Name
                <img id="priorityurl" src="@Url.Content(Model.ProjectPriorities.SingleOrDefault(p => p.PriorityID == Model.Ticket.PriorityID).ImageUrl)" alt="" />
            }
        </div>
        <div class="clear">
        </div>
    </div>
    <div class="clear">
    </div>
    <div class="editor-label" style="float: left; width: 150px">
        @Html.Label("Description"):
    </div>
    <div class="editor-field" style="float: left;">
        @Html.Raw(HtmlSanitizer.sanitize(Model.Ticket.Description));
    </div>
    <div class="clear">
    </div>
    </form>
</div>
<div class="tab-container">
    <div id="tabs">
        <ul>
            <li><a href="#tabs-2">Comments</a></li>
            <li><a href="#tabs-3">Attachments</a></li>
            <li><a href="#tabs-4">History</a></li>
            <li><a href="#tabs-5">Notification</a></li>
        </ul>
        <div id="tabs-2">
            @Html.Partial("TicketComments", Model.TicketCommentViewModel)
            @using (Ajax.BeginForm("AddComment", "Ticket", new { id = Model.Ticket.TicketID }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "comments", OnFailure = "handleFailure", OnSuccess = "ClearCommentText" }))
            { 
                <b>
                    <label for="name">
                        Comment</label></b><br />
                @Html.TextArea("comment", "", 5, 80, null)<br />
                <br />
                <input type="submit" value="Submit" />
            }
        </div>
        <div id="tabs-3">
            @Html.Partial("TicketAttachments", Model.TicketAttachmentViewModel)
        </div>
        <div id="tabs-4">
            @Html.Partial("TicketHistory", Model.TicketHistoryViewModel)
        </div>
        <div id="tabs-5">
            @Html.Partial("TicketNotifications", Model.TicketNotificationViewModel)
        </div>
    </div>
</div>
<br />
@section ScriptContent{
    <script id="DocumentReady" type="text/javascript">
        $(document).ready(function () {
            $("#tabs").tabs();
            //            $("#history").accordion({
            //                collapsible: true,
            //                active: false
            //            });
        });        
    </script>
    <script type="text/javascript" id="ChangeImageDropdownChange">
        $('#Ticket_PriorityID').change(function () {
            var url = '/Project/GetPriorityURL/' + $("#Ticket_PriorityID").val();
            $.ajax({
                type: 'POST',
                url: url,
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (response) {
                    $('#priorityurl').attr("src", response);
                }
            });
        });

        $('#Ticket_StatusID').change(function () {
            var url = '/Project/GetStatusURL/' + $("#Ticket_StatusID").val();
            $.ajax({
                type: 'POST',
                url: url,
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (response) {
                    $('#statusurl').attr("src", response);
                }
            });
        });
    </script>
}
